import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/4 16:46
 * @description 贪心，遇到所有相同的字符都移出代价最小的，只剩一个
 */
public class Solution {
    public static void main(String[] args) {

        int[] ne = { 3,5,10,7,5,3,5,5,4,8,1 };
        Solution solution = new Solution();
        solution.minCost("aaabbbabbbb", ne);

    }
    public int minCost(String colors, int[] neededTime) {
        int n = colors.length();
        char[] C = colors.toCharArray();
        int min = 0;
        for(int i = 0; i < n; i++) {
            int sum = neededTime[i];
            int maxN = neededTime[i];
            while (i + 1 < n && C[i] == C[i+1]) {
                sum += neededTime[i + 1];
                if (neededTime[i+1] > maxN) {
                    maxN = neededTime[i + 1];
                }
                i++;
            }
            min += sum - maxN;
        }
        return min;
    }
}
